package algorithm.program_beauty;

import java.util.ArrayList;
import java.util.List;

public class Pair<T> {
    private T first;
    private T second;

    public Pair(){}
    public Pair(T first,T second){
        this.first = first;
        this.second = second;
    }

    public void setFirst(T first){
        this.first = first;
    }
    public T getFirst(){
        return first;
    }
    public void setSecond(T second){
        this.second = second;
    }
    public T getSecond(){
        return second;
    }
}


/**
 * Java的泛型是在编译期间进行处理的，而不是在运行期间进行处理。比如List&lt;String&gt; 或是 Integer对JVM来讲都是List
 */
class Main {
    public static void main(String[] args) throws Exception {
//        Order order = new Order();
//        Integer[] data = {1,2,3,4};
//
//        List<Integer> integers = order.copyFormArrayToList(data);
//        System.out.println(integers);

//        List<String> strings = new ArrayList<>();
//        List<Integer> integers = new ArrayList<>();
//        strings.add("sdfsdf");
//        integers.add(123123);
//        System.out.println(strings.getClass() == integers.getClass());

        List<Integer> reflectList = new ArrayList<>();
        reflectList.add(11231);
        reflectList.getClass().getMethod("add", Object.class).invoke(reflectList, "i am string");
        System.out.println(reflectList);


    }
}


class Order {
    // 返回的是一个集合类型
    public <E> List<E> copyFormArrayToList(E[] source) {
        List<E> target = new ArrayList<>();
        for (E e : source) {
            target.add(e);
        }
        return target;
    }
}